/*
 * @Author: wangjh wangjiahui0710@163.com
 * @Date: 2024-06-11 11:33:55
 * @LastEditors: wangjh wangjiahui0710@163.com
 * @LastEditTime: 2024-06-11 15:35:41
 * @FilePath: \cip-admin\vite.proxy.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import process from "node:process";

import { HttpsProxyAgent } from "https-proxy-agent";
import type { ConfigEnv, ProxyOptions } from "vite";
import { loadEnv } from "vite";
/**
 * 创建vite开发环境代理
 * @param config
 * @returns
 */
export function createProxy(
  config: ConfigEnv,
): Record<string, string | ProxyOptions> {
  const env = loadEnv(config.mode, process.cwd());

  return {
    "/whManager": {
      //   agent: new HttpsProxyAgent("http://192.168.0.245:9081"),
      target: env.VITE_SERVER_URL_PROXY,
      changeOrigin: true,
    },
    "/resource": {
      //   agent: new HttpsProxyAgent("http://192.168.0.245:9081"),
      target: env.VITE_SERVER_URL_PROXY,
      changeOrigin: true,
    },
  };
}
